package Test_0813;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 * Dare: 2024-08-13
 * Time: 22:09
 */
//实现Cloneable接口
class IB implements Cloneable{
    public int ib=1;
    @Override
    protected Object clone()
            throws CloneNotSupportedException {
        return super.clone();
    }
}
public class Animal implements Cloneable{
    public int age;
    public String name;
    public int a=23;
    public IB b=new IB();
    public Animal(int age, String name) {
        this.age = age;
        this.name = name;
    }
    @Override
    public String toString() {
        return "Animal{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
    @Override
    protected Object clone()
            throws CloneNotSupportedException {
        Animal ani=(Animal)super.clone();
        ani.b=(IB)this.b.clone();
        return ani;
    }
}
